<?php
TImport('product');

$catid      = gpc_getIntPost('id');
$fprice      = gpc_getIntPost('fr')*100000;
$tprice      = gpc_getIntPost('to')*100000;
$Code      = gpc_getStringPost('code');
if($Code==getLang('code product'))
{
    $Code = '';
}

$products   = SearchProduct($catid,$fprice,$tprice,$Code);

function SearchProduct($catid,$fprice,$tprice,$Code)
{
    global $dbsql,$language;
    
    $sql_select = "select * from tblproduct where iStatus=1 ";
    
    if($catid>0)
    {
        $sql_select .= " and iParentId = $catid ";
    }
    if($fprice>0)
    {
        $sql_select .= " and cPrice > $fprice ";
    }
    
    if($tprice>0)
    {
        $sql_select .= " and cPrice < $tprice ";
    }
    
    if(!empty($Code))
    {
        $sql_select .= " and cCode= '$Code'";
    }
    return $dbsql->load($sql_select);
}
?>